package com.example.chapter11;


import java.util.function.Predicate;

/*
* 11.2.6.函数组合
* Predicate组合
* */
public class Demo05 {



    public static void and(){
        Predicate<String> startsWithA = (text) -> text.startsWith("A");
        Predicate<String> endsWithX   = (text) -> text.endsWith("x");

        Predicate<String> composed = startsWithA.and(endsWithX);

        String input = "A hardworking person must relax";
        boolean result = composed.test(input);
        System.out.println(result);
    }

    public static void or(){
        Predicate<String> startsWithA = (text) -> text.startsWith("A");
        Predicate<String> endsWithX   = (text) -> text.endsWith("x");

        Predicate<String> composed = startsWithA.or(endsWithX);

        String input = "A hardworking person must relax sometimes";
        boolean result = composed.test(input);
        System.out.println(result);
    }

    //and
    public static void main(String[] args) {
        and();

        or();

    }
}
